home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume17 / rotate_log / part01 next >
Encoding:
Internet Message Format  |  1991-04-04  |  18.5 KB

  1. From: scs@lokkur.dexter.mi.us (Steve Simmons)
  2. Newsgroups: comp.sources.misc
  3. Subject: v17i077:  rotate_log - logfile management utility, Part01/01
  4. Message-ID: <1991Apr4.032422.3329@sparky.IMD.Sterling.COM>
  5. Date: 4 Apr 91 03:24:22 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 546b5905 408eb05e 3b323a11 c9900530
  8.  
  9. Submitted-by: Steve Simmons <scs@lokkur.dexter.mi.us>
  10. Posting-number: Volume 17, Issue 77
  11. Archive-name: rotate_log/part01
  12.  
  13. Tired of writing yet another log trimming sequence in yet another shell
  14. script?  Then this little ditty is for you.  It rotates logs, compresses
  15. them, cleans out the old logs, kills the oldest logs, lets you invoke
  16. custom commands along the way, complains politely if anything is wrong,
  17. and has a hot cup of coffee waiting for you in the morning.
  18.  
  19. OK, it won't do the coffee.  But it does everything else, and has managed
  20. to worm it's way into crontabs all over the joint.  Today I was putting
  21. it in to clean Yet Another Log, and saw that our operators are using it,
  22. our other system programmer is using it, etc, etc.  They're even
  23. reading the man page.  Since it's such a success at work, it must
  24. be time to throw it to the wolves, er, world.  Enjoy!
  25.  
  26. Steve Simmons
  27. scs@lokkur.dexter.mi.us
  28. ----
  29. #! /bin/sh
  30. # This is a shell archive.  Remove anything before this line, then unpack
  31. # it by saving it into a file and typing "sh file".  To overwrite existing
  32. # files, type "sh file -c".  You can also feed this as standard input via
  33. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  34. # will see the following message at the end:
  35. #        "End of shell archive."
  36. # Contents:  ReadMe rotate_log rotate_log.8
  37. # Wrapped by scs@lokkur.dexter.mi.us on Wed Apr  3 19:52:54 1991
  38. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  39. if test -f 'ReadMe' -a "${1}" != "-c" ; then 
  40.   echo shar: Will not clobber existing file \"'ReadMe'\"
  41. else
  42. echo shar: Extracting \"'ReadMe'\" \(805 characters\)
  43. sed "s/^X//" >'ReadMe' <<'END_OF_FILE'
  44. XTired of writing yet another log trimming sequence in yet another shell
  45. Xscript?  Then this little ditty is for you.  It rotates logs, compresses
  46. Xthem, cleans out the old logs, kills the oldest logs, lets you invoke
  47. Xcustom commands along the way, complains politely if anything is wrong,
  48. Xand has a hot cup of coffee waiting for you in the morning.
  49. X
  50. XOK, it won't do the coffee.  But it does everything else, and has managed
  51. Xto worm it's way into crontabs all over the joint.  Today I was putting
  52. Xit in to clean Yet Another Log, and saw that our operators are using it,
  53. Xour other system programmer is using it, etc, etc.  They're even
  54. Xreading the man page.  Since it's such a success at work, it must
  55. Xbe time to throw it to the wolves, er, world.  Enjoy!
  56. X
  57. XSteve Simmons
  58. Xscs@lokkur.dexter.mi.us
  59. XApril 3, 1991
  60. END_OF_FILE
  61. if test 805 -ne `wc -c <'ReadMe'`; then
  62.     echo shar: \"'ReadMe'\" unpacked with wrong size!
  63. fi
  64. # end of 'ReadMe'
  65. fi
  66. if test -f 'rotate_log' -a "${1}" != "-c" ; then 
  67.   echo shar: Will not clobber existing file \"'rotate_log'\"
  68. else
  69. echo shar: Extracting \"'rotate_log'\" \(10991 characters\)
  70. sed "s/^X//" >'rotate_log' <<'END_OF_FILE'
  71. X: 
  72. X# Shell script to rotate a log.  Usage:
  73. X#
  74. X# rotate_log log [ -L src_dir ] [ -n n ] [ -c ] [ -B backup_dir ]
  75. X#    [ -b backup_name ] [ -m mode ] [ -o owner ] [ -g group ]
  76. X#    [ -M mode ] [ -O owner ] [ -G group ] [ -e prolog_cmd ]
  77. X#    [ -E postlog_cmd ] logfile
  78. X#
  79. X# where the switches mean:
  80. X#
  81. X#  -L    Name of the directory 'log' is found in.
  82. X#  -n    Number of backup copies to keep.
  83. X#  -c   Compress the backup copy.
  84. X#  -B   Dir to keep the backup copies in.
  85. X#  -b   Name of backup copy. 
  86. X#  -m   Mode of new log.
  87. X#  -o   Owner of new log (only root can use this option).
  88. X#  -g   Group of new log (only root can use this option).
  89. X#  -M   Mode of backup copy.
  90. X#  -O   Owner of backup copy (only root can use this option).
  91. X#  -G   Group of backup copy (only root can use this option).
  92. X#  -e    Command to be executed immediately before copying the logfile.
  93. X#  -E    Command to be executed immediately after copying the logfile.
  94. X#
  95. X# Stylistic note -- any error that says 'Unexpected error' means I
  96. X# thought this particular error can't happen.
  97. X#
  98. X# This program is Copyright 1989, Steven C. Simmons.  It may be freely
  99. X# redistributed provided this notice remains intact and any changes you
  100. X# make are clearly marked as such.
  101. X#
  102. X# $Source: /home/lokkur/scs/src/rotate_log/RCS/rotate_log,v $
  103. X#
  104. X# $Revision: 0.5 $
  105. X#
  106. X# $Author: scs $    $Date: 91/04/03 19:49:00 $
  107. X#
  108. X# $State: Exp $    $Locker:  $
  109. X#
  110. X# $Log:    rotate_log,v $
  111. X# Revision 0.5  91/04/03  19:49:00  scs
  112. X# Parameterized locations of chmod, chgrp, chown.
  113. X# 
  114. X# Revision 0.4  89/12/12  09:35:59  scs
  115. X# Bug fixes to pick up more defaults.
  116. X# 
  117. X# Revision 0.3  89/12/11  21:34:25  scs
  118. X# Broke out commands separately to avoid ksh wierdness.  Ported
  119. X# to system V.2 sh, ksh.  Removed some BSDisms that makes it more
  120. X# portable.
  121. X# 
  122. X# Revision 0.2  89/12/11  20:53:51  scs
  123. X# Improved error checking on source directory.  Corrected erroneous
  124. X# error message.
  125. X# 
  126. X# Revision 0.1  89/12/11  19:39:31  scs
  127. X# Initial revision.
  128. X# 
  129. XSCRIPT=`basename $0`
  130. X#
  131. X#  Commonly used commands
  132. X#
  133. XMV=/bin/mv
  134. XCP=/bin/cp
  135. XCHMOD=/bin/chmod
  136. XCHOWN=/etc/chown
  137. XCHGRP=/bin/chgrp
  138. X#
  139. X#  Assign default values as needed
  140. X#
  141. XSOURCE_DIR=""
  142. XSOURCE_NAME=""
  143. XBACKUP_NAME=""
  144. XBACKUP_DIR=""
  145. XBACKUP_COUNT="3"
  146. XCOMPRESS=""
  147. XSOURCE_MODE=""
  148. XSOURCE_OWNER=""
  149. XSOURCE_GROUP=""
  150. XBACKUP_MODE=""
  151. XBACKUP_OWNER=""
  152. XBACKUP_GROUP=""
  153. X#
  154. X#  Basic switch parsing.  Right now, this forces us to use whitespace
  155. X#  between switch char and actual execution.  Whenever we get data
  156. X#  for a switch, errorcheck it immediately.
  157. X#
  158. Xwhile [ "$#" -gt "0" ] ; do
  159. X    case $1 in
  160. X    -L )    if [ "$2" = "" ] ; then
  161. X            echo "${SCRIPT}: The $1 switch requires a directory name.  Aborting."
  162. X            exit 0
  163. X        fi
  164. X        if [ -w "${2}" -a -d "${2}" ] ; then
  165. X            :
  166. X        else
  167. X            echo "${SCRIPT}: Sorry, you cannot modify the directory ${2}.  Aborting."
  168. X            exit 0
  169. X        fi
  170. X        SOURCE_DIR="${2}/"
  171. X        shift
  172. X        ;;
  173. X    -b )    if [ "$2" = "" ] ; then
  174. X            echo "${SCRIPT}: The $1 switch requires a backup name.  Aborting."
  175. X            exit 0
  176. X        fi
  177. X        BACKUP_NAME="$2"
  178. X        shift
  179. X        ;;
  180. X    -B )    if [ "$2" = "" ] ; then
  181. X            echo "${SCRIPT}: The $1 switch requires a directory name.  Aborting."
  182. X            exit 0
  183. X        fi
  184. X        if [ -w "${2}" -a -d "${2}" ] ; then
  185. X            :
  186. X        else
  187. X            echo "${SCRIPT}: Sorry, you cannot create files in ${DIR}.  Aborting."
  188. X            exit 0
  189. X        fi
  190. X        BACKUP_DIR="${2}/"
  191. X        shift
  192. X        ;;
  193. X    -n )    if [ "$2" = "" ] ; then
  194. X            echo "${SCRIPT}: The $1 switch requires a backup count.  Aborting."
  195. X            exit 0
  196. X        fi
  197. X        if echo $2 | grep '[^0-9]' > /dev/null 2>&1 ; then
  198. X            echo "${SCRIPT}: The backup count ($2) must be a positive number.  Aborting."
  199. X            exit 0
  200. X        fi
  201. X        if [ $2 -eq 0 ] ; then
  202. X            echo "${SCRIPT}: The backup count ($2) must be greater than zero.  Aborting."
  203. X            exit 0
  204. X        fi
  205. X        BACKUP_COUNT="$2"
  206. X        shift
  207. X        ;;
  208. X    -c )    COMPRESS="compress"
  209. X        ;;
  210. X    -m )    if [ "$2" = "" ] ; then
  211. X            echo "${SCRIPT}: The $1 switch requires a permissions mode.  Aborting."
  212. X            exit 0
  213. X        fi
  214. X        SOURCE_MODE="$CHMOD $2"
  215. X        shift
  216. X        ;;
  217. X    -M )    if [ "$2" = "" ] ; then
  218. X            echo "${SCRIPT}: The $1 switch requires a permissions mode.  Aborting."
  219. X            exit 0
  220. X        fi
  221. X        BACKUP_MODE="$CHMOD $2"
  222. X        shift
  223. X        ;;
  224. X    -o )    if [ "$2" = "" ] ; then
  225. X            echo "${SCRIPT}: The $1 switch requires the name of the new owner.  Aborting."
  226. X            exit 0
  227. X        fi
  228. X        if grep '^${2}:' < /etc/passwd > /dev/null 2>&1 ; then
  229. X            echo "${SCRIPT}: No such login id as $2.  Aborting."
  230. X            exit 0
  231. X        fi
  232. X        SOURCE_OWNER="$CHOWN $2"
  233. X        shift
  234. X        ;;
  235. X    -O )    if [ "$2" = "" ] ; then
  236. X            echo "${SCRIPT}: The $1 switch requires the name of the new owner.  Aborting."
  237. X            exit 0
  238. X        fi
  239. X        if grep '^${2}:' < /etc/passwd > /dev/null 2>&1 ; then
  240. X            echo "${SCRIPT}: No such login id as $2.  Aborting."
  241. X            exit 0
  242. X        fi
  243. X        BACKUP_OWNER="$CHOWN $2"
  244. X        shift
  245. X        ;;
  246. X    -g )    if [ "$2" = "" ] ; then
  247. X            echo "${SCRIPT}: The $1 switch requires the name of the new group.  Aborting."
  248. X            exit 0
  249. X        fi
  250. X        if grep '^${2}:' < /etc/group > /dev/null 2>&1 ; then
  251. X            echo "${SCRIPT}: No such group as $2.  Aborting."
  252. X            exit 0
  253. X        fi
  254. X        SOURCE_GROUP="$CHGRP $2"
  255. X        shift
  256. X        ;;
  257. X    -G )    if [ "$2" = "" ] ; then
  258. X            echo "${SCRIPT}: The $1 switch requires the name of the new group.  Aborting."
  259. X            exit 0
  260. X        fi
  261. X        if grep '^${2}:' < /etc/group > /dev/null 2>&1 ; then
  262. X            echo "${SCRIPT}: No such group as $2.  Aborting."
  263. X            exit 0
  264. X        fi
  265. X        BACKUP_GROUP="$CHGRP $2"
  266. X        shift
  267. X        ;;
  268. X    -e )    if [ "$2" = "" ] ; then
  269. X            echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
  270. X            exit 0
  271. X        fi
  272. X        CMD_BEFORE="${2}"
  273. X        shift
  274. X        ;;
  275. X    -E )    if [ "$2" = "" ] ; then
  276. X            echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
  277. X            exit 0
  278. X        fi
  279. X        CMD_AFTER="${2}"
  280. X        shift
  281. X        ;;
  282. X    -* )    echo "${SCRIPT}: No such switch as $1.  Aborting."
  283. X        exit 0
  284. X        ;;
  285. X    * )    if [ "${SOURCE_NAME}" != "" ] ; then
  286. X            echo "${SCRIPT}: You must specify only one log file.  Aborting."
  287. X            exit 0
  288. X        else
  289. X            SOURCE_NAME=$1
  290. X        fi
  291. X        ;;
  292. X    esac
  293. X    shift
  294. Xdone
  295. Xif [ "${SOURCE_NAME}" = "" ] ; then
  296. X    echo "${SCRIPT}: You must specify a log file.  Aborting."
  297. X    exit 0
  298. Xfi
  299. X#
  300. X#  Do sanity checks
  301. X#
  302. X#  If he specified a source directory or backup directory, the source
  303. X#  and backup file names cannot contain a slash.
  304. X#
  305. Xif [ "${SOURCE_DIR}" != "" ] ; then
  306. X    if echo $SOURCE_NAME | grep / > /dev/null ; then
  307. X        cat << EOF
  308. X${SCRIPT}: If you specify a source directory (eg, -L ${SOURCE_DIR}),
  309. Xthen the log file name (${SOURCE_NAME}) must be a simple file name,
  310. Xie, not containing any slashes.  Aborting.
  311. XEOF
  312. X        exit 0
  313. X    fi
  314. X    #
  315. X    #  If they don't explicitly select a backup directory but the
  316. X    #  do specify a log directory, use the same for both.
  317. X    #
  318. X    if [ "${BACKUP_DIR}" = "" ] ; then
  319. X        BACKUP_DIR="${SOURCE_DIR}"
  320. X    fi
  321. Xfi
  322. Xif [ "${BACKUP_DIR}" != "" ] ; then
  323. X    if echo $BACKUP_NAME | grep / > /dev/null ; then
  324. X        cat << EOF
  325. X${SCRIPT}: If you specify a backup directory (eg, -B ${BACKUP_DIR}),
  326. Xthen the backup log name (${BACKUP_NAME}) must be a simple file name,
  327. Xie, not containing any slashes.  Aborting.
  328. XEOF
  329. X        exit 0
  330. X    fi
  331. Xfi
  332. X#
  333. X#  Make sure we can mod the directory where the log is.
  334. X#
  335. Xif [ -w `dirname "${SOURCE_NAME}"` ] ;  then
  336. X    :
  337. Xelse
  338. X    cat << EOF
  339. X${SCRIPT}: Sorry, you do not have permission to move/rename the
  340. Xlog file (file '`basename ${SOURCE_NAME}`', directory '`dirname ${SOURCE_NAME}`').  Aborting.
  341. XEOF
  342. X    exit 0
  343. Xfi
  344. X#
  345. X#  Make sure we can read/write the log itself.
  346. X#
  347. XSOURCE_PATH="${SOURCE_DIR}${SOURCE_NAME}"
  348. Xif [ -w "${SOURCE_PATH}" -a -r "${SOURCE_PATH}" ] ; then
  349. X    :
  350. Xelse
  351. X    echo "${SCRIPT}: Sorry, you do not have permission to read and modify"
  352. X    echo "the file '${SOURCE_PATH}'.  Aborting."
  353. X    exit 0
  354. Xfi
  355. X#
  356. X#  Make sure root operations are only run by root
  357. X#
  358. Xif [ "${BACKUP_OWNER}" != "" -o "${SOURCE_OWNER}" != "" -o "${BACKUP_GROUP}" != "" -o "${SOURCE_GROUP}" != "" ]
  359. Xthen
  360. X    set `who am i`
  361. X    if [ "root" != "$1" ] ; then
  362. X        echo "${SCRIPT}: Sorry, you can only change owner or group if you are root."
  363. X        echo "Aborting."
  364. X        exit 0
  365. X    fi
  366. Xfi
  367. X#
  368. X#  Build the list of backup names, in reverse order.  Make them
  369. X#  full pathnames.
  370. X#
  371. Xif [ "${BACKUP_NAME}" = "" ] ; then
  372. X    BACKUP_NAME="${SOURCE_NAME}"
  373. Xfi
  374. Xwhile expr $BACKUP_COUNT \> 0 > /dev/null ; do
  375. X    BACKUP_COUNT=`expr $BACKUP_COUNT - 1`
  376. X    BACKUP_FILES="${BACKUP_FILES} ${BACKUP_DIR}${BACKUP_NAME}.${BACKUP_COUNT}"
  377. Xdone
  378. X#
  379. X#  Rotate the existing backups.  Assume no change in permissions, etc.
  380. X#
  381. Xset ${BACKUP_FILES}
  382. Xif [ "${1}" = "" ] ; then
  383. X    echo "${SCRIPT}: unexpected error in using backup list.  Aborting."
  384. X    exit 0
  385. Xfi
  386. XOLDEST="${1}"
  387. Xshift
  388. Xwhile [ "$1" != "" ] ; do
  389. X    NEXT="${1}"
  390. X    rm -f "${OLDEST}" "${OLDEST}.Z"
  391. X    if [ -f "${NEXT}" ] ; then
  392. X        ${MV} "${NEXT}" "${OLDEST}"
  393. X    elif [ -f "${NEXT}.Z" ] ; then
  394. X        ${MV} "${NEXT}.Z" "${OLDEST}.Z"
  395. X    else
  396. X        echo "${SCRIPT}: Missing backup log ${NEXT} or ${NEXT}.Z.  Continuing."
  397. X    fi
  398. X    OLDEST="${NEXT}"
  399. X    shift
  400. Xdone
  401. X#
  402. X#  Copy the current log to be the first backup.  Use full pathnames
  403. X#  as appropriate.
  404. X#
  405. Xif [ "${SOURCE_DIR}" != "" ] ; then
  406. X    if cd "${SOURCE_DIR}" ; then
  407. X        :
  408. X    else
  409. X        echo "${SCRIPT}: unexpected error in command 'cd ${SOURCE_DIR}'.  Aborting."
  410. X        exit 0
  411. X    fi
  412. Xfi
  413. Xrm -f "${NEXT}" "${NEXT}.Z"
  414. Xif [ "${CMD_BEFORE}" != "" ] ; then
  415. X    ${CMD_BEFORE}
  416. Xfi
  417. Xif ${MV} "${SOURCE_NAME}" "${NEXT}" ; then
  418. X    :
  419. Xelse
  420. X    echo "${SCRIPT}: unexpected error making first backup.  Aborting."
  421. X    exit 0
  422. Xfi
  423. Xif [ "${CMD_AFTER}" != "" ] ; then
  424. X    ${CMD_AFTER}
  425. Xfi
  426. Xrm -f "${SOURCE_NAME}" "${SOURCE_NAME}".Z
  427. Xif cat > "${SOURCE_NAME}" < /dev/null ; then
  428. X    :
  429. Xelse
  430. X    echo "${SCRIPT}: unexpected error emptying log file.  Continuing."
  431. Xfi
  432. X#
  433. X#  Set ownership and permission on the log as requested.
  434. X#
  435. Xif [ "${SOURCE_MODE}" != "" ] ; then
  436. X    if ${CHMOD} ${SOURCE_MODE} "${SOURCE_NAME}" ; then
  437. X        :
  438. X    else
  439. X        echo "${SCRIPT}: unexpected error executing command '${CHMOD} ${SOURCE_MODE} ${SOURCE_NAME}'."
  440. X        echo "Aborting."
  441. X        exit 0
  442. X    fi
  443. Xfi
  444. Xif [ "${SOURCE_OWNER}" != "" ] ; then
  445. X    if ${CHOWN} ${SOURCE_OWNER} "${SOURCE_NAME}" ; then
  446. X        :
  447. X    else
  448. X        echo "${SCRIPT}: unexpected error executing command '${CHOWN} ${SOURCE_OWNER} ${SOURCE_NAME}'."
  449. X        echo "Aborting."
  450. X        exit 0
  451. X    fi
  452. Xfi
  453. Xif [ "${SOURCE_GROUP}" != "" ] ; then
  454. X    if ${CHGRP} ${SOURCE_GROUP} "${SOURCE_NAME}" ; then
  455. X        :
  456. X    else
  457. X        echo "${SCRIPT}: unexpected error executing command '${CHGRP} ${SOURCE_GROUP} ${SOURCE_NAME}'."
  458. X        echo "Aborting."
  459. X        exit 0
  460. X    fi
  461. Xfi
  462. X#
  463. X#  Set ownerships and permissions as requested on the backed up log.
  464. X#  Note that the compress must come last in this sequence.
  465. X#
  466. Xif [ "${BACKUP_MODE}" != "" ] ; then
  467. X    if ${CHMOD} ${BACKUP_MODE} "${NEXT}" ; then
  468. X        :
  469. X    else
  470. X        echo "${SCRIPT}: unexpected error executing command '${CHMOD} ${BACKUP_MODE} ${NEXT}'."
  471. X        echo "Aborting."
  472. X        exit 0
  473. X    fi
  474. Xfi
  475. Xif [ "${BACKUP_OWNER}" != "" ] ; then
  476. X    if ${CHOWN} ${BACKUP_OWNER} "${NEXT}" ; then
  477. X        :
  478. X    else
  479. X        echo "${SCRIPT}: unexpected error executing command '${CHOWN} ${BACKUP_OWNER} ${NEXT}'."
  480. X        echo "Aborting."
  481. X        exit 0
  482. X    fi
  483. Xfi
  484. Xif [ "${BACKUP_GROUP}" != "" ] ; then
  485. X    if ${CHGRP} ${BACKUP_GROUP} "${NEXT}" ; then
  486. X        :
  487. X    else
  488. X        echo "${SCRIPT}: unexpected error executing command '${CHGRP} ${BACKUP_GROUP} ${NEXT}'."
  489. X        echo "Aborting."
  490. X        exit 0
  491. X    fi
  492. Xfi
  493. Xif [ "${COMPRESS}" != "" ] ; then
  494. X    if ${COMPRESS} "${NEXT}" ; then
  495. X        :
  496. X    else
  497. X        echo "${SCRIPT}: unexpected error executing command '${COMPRESS} ${NEXT}'."
  498. X        echo "Aborting."
  499. X        exit 0
  500. X    fi
  501. Xfi
  502. END_OF_FILE
  503. if test 10991 -ne `wc -c <'rotate_log'`; then
  504.     echo shar: \"'rotate_log'\" unpacked with wrong size!
  505. fi
  506. chmod +x 'rotate_log'
  507. # end of 'rotate_log'
  508. fi
  509. if test -f 'rotate_log.8' -a "${1}" != "-c" ; then 
  510.   echo shar: Will not clobber existing file \"'rotate_log.8'\"
  511. else
  512. echo shar: Extracting \"'rotate_log.8'\" \(3321 characters\)
  513. sed "s/^X//" >'rotate_log.8' <<'END_OF_FILE'
  514. X.\" Manual page for rotate_log
  515. X.\"
  516. X.\" $Source: /home/lokkur/scs/src/rotate_log/RCS/rotate_log.8,v $
  517. X.\"
  518. X.\" $Revision: 1.3 $
  519. X.\"
  520. X.\" $Author: scs $    $Date: 89/12/11 17:54:30 $
  521. X.\"
  522. X.\" $State: Exp $    $Locker: scs $
  523. X.\"
  524. X.\" $Log:    rotate_log.8,v $
  525. X."\ Revision 1.3  89/12/11  17:54:30  scs
  526. X."\ Added prolog and postlog commands.
  527. X."\ 
  528. X."\ Revision 1.2  89/12/11  17:34:46  scs
  529. X."\ Corrected minor format errors.
  530. X."\ 
  531. X."\ Revision 1.1  89/12/11  17:29:36  scs
  532. X."\ Initial revision
  533. X."\ 
  534. X.TH ROTATE_LOG 8 89/12/11
  535. X.SH NAME
  536. Xrotate_log \- rotate logfiles, removing the oldest
  537. X.SH SYNOPSIS
  538. X.B
  539. Xrotate_log log [ \-L log_dir ] [ \-n n ] [ \-c ] [ \-B backup_dir ] [ \-b backup_name ] [ \-m mode ] [ \-o owner ] [ \-g group ] [ \-M mode ] [ \-O owner ] [ \-G group ] [ -e "prolog_command" ] [ -E "postlog_command" ] logfile
  540. X.R
  541. X.SH DESCRIPTION
  542. X.B Rotate_log
  543. Xtakes a lot of the drudgery out of managing logfiles.
  544. XIt assume you have a log file
  545. X.I logfile
  546. Xand a series of backup copies
  547. X.I "logfile.0,"
  548. X.I "logfile.1,"
  549. Xetc,
  550. Xwhere 
  551. X.I 0
  552. Xis the newest backup and
  553. X.I N
  554. Xis the oldest.
  555. X.B Rotate_log
  556. Xwill remove the oldest,
  557. Xrename the rest,
  558. Xand empty out the original
  559. X.I logfile.
  560. XIt has lots of options to let you control things:
  561. X.TP
  562. X.B "\-L log_dir"
  563. XAssume the
  564. X.I logfile
  565. Xis in a directory named
  566. X.I log_dir.
  567. X.TP
  568. X.B "\-n n"
  569. XUse
  570. X.I n
  571. Xbackups.
  572. XIf you don't set this, it defaults to three.
  573. X.TP
  574. X.B "\-c"
  575. X.I Compress(1)
  576. Xthe backup copies.
  577. X.TP
  578. X.B "\-B backup_dir"
  579. XPut the backed up log copies in the directory
  580. X.I backup_dir.
  581. X.TP
  582. X.B "\-b backup_name"
  583. XName the backed up log copies
  584. X.I backup_name.
  585. XNote you can use both the 
  586. X.B \-B
  587. Xand
  588. X.B \-b
  589. Xswitches at the same time.
  590. X.TP
  591. X.B "\-m mode"
  592. XSet the mode (permissions) on
  593. X.I logfile
  594. Xto
  595. X.I mode.
  596. X.TP
  597. X.B "\-o owner"
  598. XSet the ownership of
  599. X.I logfile
  600. Xto
  601. X.I owner
  602. X(this option is only available to 
  603. X.I root ).
  604. X.TP
  605. X.B "\-g group"
  606. XSet the group membership of
  607. X.I logfile
  608. Xto
  609. X.I group
  610. X(this option is only available to 
  611. X.I root ).
  612. X.TP
  613. X.B "\-M mode"
  614. XSet the mode (permissions) on
  615. X.I logfile.0
  616. Xto
  617. X.I mode.
  618. X.TP
  619. X.B "\-O owner"
  620. XSet the ownership of
  621. X.I logfile.0
  622. Xto
  623. X.I owner
  624. X(this option is only available to 
  625. X.I root ).
  626. X.TP
  627. X.B "\-O group"
  628. XSet the group membership of
  629. X.I logfile.0
  630. Xto
  631. X.I group
  632. X(this option is only available to 
  633. X.I root ).
  634. X.TP
  635. X.B "\-e prolog_command"
  636. X.I prolog_command
  637. Xis a command to be executed just before moving
  638. X.I logfile
  639. Xto
  640. X.I logfile.0.
  641. XNote that if 
  642. X.I prolog_command
  643. Xhas spaces, blanks, or metacharacters they must be quoted.
  644. X.TP
  645. X.B "\-E postlog_command"
  646. X.I prolog_command
  647. Xis a command to be executed immediately after emptying
  648. X.I logfile
  649. XNote it is only executed if
  650. X.I logfile
  651. Xis successfully emptied.
  652. XNote also that if 
  653. X.I prolog_command
  654. Xhas spaces, blanks, or metacharacters they must be quoted.
  655. X.PP
  656. XNote that the mode and ownership settings apply only the the newly
  657. Xcreated backups.
  658. XIt is assumed that all older backups are already set as desired.
  659. X.SH "ERROR MESSAGES"
  660. XHopefully self-explaining.
  661. XThis command bends over backwards checking for permission before
  662. Xtrying things,
  663. Xand tries very hard to be informative when something isn't right.
  664. X.SH FILES
  665. XNone.
  666. X.SH AUTHOR
  667. XSteve Simmons
  668. X.SH "COPYRIGHT STATUS"
  669. XCopyright 1989 Steve Simmons
  670. X.I (scs@lokkur.dexter.mi.us).
  671. XFreely redistributable provided this copyright remains intact.
  672. X.SH BUGS
  673. XPlease report them to the author, scs@lokkur.dexter.mi.us.
  674. END_OF_FILE
  675. if test 3321 -ne `wc -c <'rotate_log.8'`; then
  676.     echo shar: \"'rotate_log.8'\" unpacked with wrong size!
  677. fi
  678. # end of 'rotate_log.8'
  679. fi
  680. echo shar: End of shell archive.
  681. exit 0
  682.  
  683. exit 0 # Just in case...
  684. -- 
  685. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  686. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  687. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  688. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  689.